package com.luisliuyi.demo.optimize.network;

import java.net.MalformedURLException;
import java.net.URL;

public class HttpUrl {
    public String file;
    public String protocol;
    public int port;
    public String host;
    public HttpUrl(String url) {
        try {
            URL localUrl = new URL(url);//url格式化
            host = localUrl.getHost();
            protocol = localUrl.getProtocol();
            port = localUrl.getPort();
            file = localUrl.getFile();
            if (port == -1) {
                //代表url中没有端口信息，就是使用默认端口，http:80,https:443
                port = localUrl.getDefaultPort();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }
}
